package fr.kyvos.optimization;

import java.io.IOException;
import java.util.Date;
import java.util.concurrent.atomic.AtomicReference;

public class TabouMethodTestThread extends AlgoTestThread {
	
	protected int[] list_tabou_sizes_range;
	
	public TabouMethodTestThread(KnapSackProblem problem) {
		super(problem);
		list_tabou_sizes_range = new int[]{};
	}
	
	public void change_config(int type_solution_init, int[] nb_iterations_range, int nb_iteration_range_pas, int[] list_tabou_sizes_range){
		super.change_config(list_tabou_sizes_range.length, type_solution_init, nb_iterations_range, nb_iteration_range_pas);
		this.list_tabou_sizes_range = list_tabou_sizes_range;
	}
	
	@Override
	protected void write_file_header() throws IOException {
		// TODO Auto-generated method stub
		super.write_file_header();
		write_in_file(";best iteration;");
		write_in_file("execution time;");
		write_in_file("taille de la liste tabou\r\n");
	}
	
	@Override
	protected void test(int no_combinaison, int nb_iterations) {
		// TODO Auto-generated method stub
		try {
			System.out.println("test actuel : nb_iterations_range : "+nb_iterations+" - list_tabou_sizes_range : "+(list_tabou_sizes_range[no_combinaison]));
			
			Date begin = new Date();
			Date end = new Date();
			AtomicReference<Date> ref = new AtomicReference<Date>(end);
			problem.initFirstSolution(type_solution_init);
			
			int no_iteration_best_fitness = problem.doMethodeTaboue(list_tabou_sizes_range[no_combinaison], nb_iterations, ref);
			double meilleur_fitness = problem.mBestSolution.getFitness();
			
			end = ref.get();
			long execution_time = end.getTime() - begin.getTime();
			
			String test_line = ""+(no_combinaison+1)+";"+nb_iterations+";"+meilleur_fitness+";"+no_iteration_best_fitness+";"+execution_time+";"+list_tabou_sizes_range[no_combinaison]+"\r\n";
			write_in_file(test_line);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
